<script type="text/javascript" src="/assets/public/jquery/jquery-2.1.0.min.js"></script>
<div id="createOrder">测试支付</div>
<script type="text/javascript">
	$(function(){
		$('#createOrder').on('click',function(){
			$.ajax({
				url:"{BEESCRM::U('Base/Test/testAdd')}",
				type:"post",
				data:{'openid':"oO2tFt0CFyhE-DmmZwf0ErRtTA0M",'money':0.01,'notify':'http://wap.alpha.greencampus.cc/base/test/notifys'},
				dataType:"json",
				success:function(data){
					if(data.retCode == '1001'){
                        alert(data.msg);
                    }else{
                       // var id = data.data.order_id;
                        var wxpay = $.parseJSON(data.wxpay);
                        pay(wxpay);
                    }
				}
			})
		})


		 //微支付
        function pay(wxpay){
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                WeixinJSBridge.invoke(
                        'getBrandWCPayRequest',
                        wxpay,
                        function(res){
                            WeixinJSBridge.log(res.err_msg);
                            alert(JSON.stringify(res))
                            if(res.err_msg == "get_brand_wcpay_request:ok"){
                                //paySuccess(id);
                                alert('成功')
                            }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                                alert('付款已取消');
                                return false;
                            }else{
//							$.alert('error','调用微支付失败');
                                alert(res.err_msg);
                                return false;
                            }
                        }
                );
            }
        }
	})
</script>